﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Web.er_index
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // Web.AppCode.Sys_Config.IntiCity("aomen");
            //string ss = Web.AppCode.Sys_Config.GetCurrentCityCode();
            if (Request["tid"] == null)
                Response.Redirect("~/index.aspx");
            Bind();
        }
        private void Bind()
        {
            //资讯前线
            DataSet infoDs = (new Controller.InformationShow()).GetRight_Iframe_Index(8,Web.AppCode.Sys_Config.GetCurrentCityCode(),Request["tid"].ToString());
             rptinfoList8.DataSource = infoDs.Tables[0].DefaultView;
             rptinfoList8.DataBind();

             DataSet ds = (new Controller.CorpInfoShow()).GetIndexMore(Web.AppCode.Sys_Config.GetCurrentCityCode());
            //红店铺
             DataView dvHot = ds.Tables[0].DefaultView;
             dvHot.Sort = " Hits desc,Sort desc";
             dvHot = GetTopDataViewRows(dvHot, 6);
              rptCorphot6.DataSource = dvHot;
              rptCorphot6.DataBind();

              //新店铺
              DataView dvNew = ds.Tables[0].DefaultView;
              dvNew.Sort = " CreateOn desc,Sort desc";
              dvNew = GetTopDataViewRows(dvNew, 6);
              rptCorpNew6.DataSource = dvNew;
              rptCorpNew6.DataBind();

              //推荐
              DataView dvGood = ds.Tables[0].DefaultView;
              dvGood.Sort = " Sort desc,Hits desc";
              dvGood = GetTopDataViewRows(dvGood, 6);
               rptCorpgood6.DataSource = dvGood;
               rptCorpgood6.DataBind();

             

        }
        private DataView GetTopDataViewRows(DataView dv, int n)
        {
            DataTable dt = dv.Table.Clone();

            for (int i = 0; i <= n - 1; i++)
            {
                if (i >= dv.Count)
                {
                    break;
                }
                dt.ImportRow(dv[i].Row);
            }

            return new DataView(dt, dv.RowFilter, dv.Sort, dv.RowStateFilter);
        }
    }
}
